/*
 * Copyright 2010 Mttang.com All right reserved. This software is the confidential and proprietary information of
 * Mttang.com ("Confidential Information"). You shall not disclose such Confidential Information and shall use it only
 * in accordance with the terms of the license agreement you entered into with Mttang.com.
 */
package com.mttang.info.core;

import java.util.HashMap;
import java.util.Map;

import com.mttang.framework.core.paginated.util.PagedFliper;

/**
 * 类ParameterModelWrapper.java的实现描述：查询参数封装
 * 
 * @author caizhan 2010-6-2 上午08:23:13
 */
public class ParameterModelWrapper {

    public final static String K_startIndex = "startIndex";
    public final static String K_endIndex   = "endIndex";

    private ParameterModel     parameterModel;

    public ParameterModelWrapper(ParameterModel parameterModel) {
        super();
        this.parameterModel = parameterModel;
    }

    /**
     * 封装所有参数信息为map，包括条件，排序，分页等
     * 
     * @return map
     */
    public Map<String, Object> wrap() {

        // 原查询条件
        Map<String, Object> param = parameterModel.getPramater();
        if (param == null) {
            param = new HashMap<String, Object>();
        }

        // 封装分页信息
        PagedFliper page = parameterModel.getPagedFliper();

        if (page == null) {
            page = new PagedFliper();
            page.setIndex(0);
            page.setPageNo(1);
            page.setPageSize(Integer.MAX_VALUE);
            parameterModel.setPagedFliper(page);
        }
        param.put(K_startIndex, Long.valueOf(page.getStartIndex() + 1));
        param.put(K_endIndex, Long.valueOf(page.getEndIndex()));

        return param;
    }
}
